home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Applications / Conic Sections 0.9.2 / Sources / MenuHandler.cpp < prev    next >
Encoding:
Text File  |  1997-07-20  |  3.4 KB  |  150 lines  |  [TEXT/CWIE]

  1. //Copyright (c) 1997 Aidan Cully
  2. //All rights reserved
  3.  
  4. #include <Dialogs.h>
  5. #include "MenuHandler.h"
  6. #include "CLApplication.h"
  7. #include "ConicContent.h"
  8. #include "ConicViewManager.h"
  9. #include "DrawContent.h"
  10. #include "CLOffScreen.h"
  11. #include "EquNew.h"
  12. #include "CLWindowLayer.h"
  13. #include "CLModalWindow.h"
  14. #include "AboutContent.h"
  15.  
  16. TConicHandler::TConicHandler( Boolean hasDD, MActionHandler *superAction ):
  17.     MActionHandler( superAction )
  18. {
  19.     mConicWindow = 0l;
  20.     mControlWindow = 0l;
  21.     mEquWindow = 0l;
  22.     mPlotWindow = 0l;
  23.     mHasDragDrop= hasDD;
  24. }
  25.  
  26. TConicHandler::~TConicHandler()
  27. {
  28.     delete mConicWindow;
  29.     delete mControlWindow;
  30.     delete mEquWindow;
  31.     delete mPlotWindow;
  32. }
  33.  
  34. SInt8 TConicHandler::Init()
  35. {
  36.     MenuHandle appleMenu;
  37.     Handle theMBar = GetNewMBar( 128 );
  38.     TLayoutLeaf *layout;
  39.     Rect begRect;
  40.     Boolean binding[]= {true, true, true, true};
  41.  
  42.     mConic.Init();
  43.     mPlane.Init();
  44.     ::SetRect( &begRect, 0, 0, 0, 0 );
  45.  
  46.     layout= new TConicContent( 0, this, mHasDragDrop, &mConic, &mPlane, -50.0, -55.0 );
  47.     //layout= new TScrollStyleBox( 0, 128 );
  48.     layout->Init();
  49.     mConicWindow = new TOffScreen( kConicWindowID, gNormalWindowLayer, layout );
  50.     layout= new TPlotContent( 0, this, mHasDragDrop, &mConic, &mPlane );
  51.     layout->Init();
  52.     mPlotWindow = new TOffScreen( kPlotWindowID, gNormalWindowLayer, layout );
  53.     layout= new TEquContent( 0, this, mHasDragDrop, &mPlane );
  54.     layout->Init();
  55.     mEquWindow = new TOffScreen( kEquWindowID, gNormalWindowLayer, layout );
  56.     layout= new TViewManagerHolder( 0, &mConic, &mPlane );
  57.     layout->Init();
  58.     mControlWindow = new TBaseWindow( kControlWindowID, gFloatingWindowLayer, layout );
  59.     mControlWindow->Init();
  60.     mConicWindow->Init();
  61.     mPlotWindow->Init();
  62.     mEquWindow->Init();
  63.  
  64.     mPlane.RotPlane();
  65.     mConic.CalcIntersect( mPlane );
  66.     mControlWindow->DoShowWindow();
  67.     mEquWindow->DoShowWindow();
  68.     mPlotWindow->DoShowWindow();
  69.     mConicWindow->DoShowWindow();
  70.     mConicWindow->SelectWindow();
  71.  
  72.     SetMenuBar( theMBar );
  73.     if( theMBar ) {
  74.         appleMenu = GetMenuHandle( m_APPLE );
  75.         DisposeHandle( theMBar );
  76.         AppendResMenu( appleMenu, 'DRVR' );
  77.         DrawMenuBar();
  78.         return( true );
  79.     }
  80.     return( false );
  81. }
  82.  
  83. SInt8 TConicHandler::HandleAction( UInt32 actionID )
  84. {
  85.     UInt16 theMenu, menuID;
  86.  
  87.     theMenu = (actionID>>16);
  88.     menuID = (actionID&0x0000FFFF);
  89.     switch( theMenu ) {
  90.     case m_APPLE:
  91.         switch( menuID )
  92.         {
  93.         case ma_ABOUT: {
  94.             TModalWindow *win;
  95.             TLayoutLeaf *content= new TAboutContent( 0 );
  96.             content->Init();
  97.             win= new TModalWindow( 130, content );
  98.             win->EventLoop();
  99.             delete win;
  100.         }; break;
  101.         default:
  102.             OpenDeskAcc( actionID );
  103.             break;
  104.         }
  105.         break;
  106.     case m_FILE:
  107.         switch( menuID )
  108.         {
  109.         case mf_CLOSE: {
  110.             TBaseWindow *win= gNormalWindowLayer->FrontWindow();
  111.             if( !win ) {
  112.                 WindowRef ref= FrontWindow();
  113.                 if( ref )
  114.                     win= ((TBaseWindow*)GetWRefCon( ref ));
  115.             }
  116.             if( win )
  117.                 win->DoHideWindow();
  118.         }; break;
  119.         case mf_QUIT:
  120.             TApplication::SCurApp()->AttemptQuit();
  121.             break;
  122.         }
  123.         break;
  124.     case m_WINDOW:
  125.         switch( menuID )
  126.         {
  127.         case mw_CONIC:
  128.             if( !mConicWindow->IsOpen() )
  129.                 mConicWindow->DoShowWindow();
  130.             mConicWindow->SelectWindow();
  131.             break;
  132.         case mw_PLOT:
  133.             if( !mPlotWindow->IsOpen() )
  134.                 mPlotWindow->DoShowWindow();
  135.             mPlotWindow->SelectWindow();
  136.             break;
  137.         case mw_CONTROL:
  138.             if( !mControlWindow->IsOpen() )
  139.                 mControlWindow->DoShowWindow();
  140.             break;
  141.         case mw_EQU:
  142.             if( !mEquWindow->IsOpen() )
  143.                 mEquWindow->DoShowWindow();
  144.             mEquWindow->SelectWindow();
  145.             break;
  146.         }
  147.         break;
  148.     }
  149.     HiliteMenu( 0 );
  150. }